package com.leetcode.day7_30;

/**
 * author: the_ring
 * Time: 2021/7/30 18:28
 * log: 无重复字符的最长子串 https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
 */

public class Code2 {

    // 实现了最长递增子序列，不是最长字串，最长子串是连续的
//    public static int lengthOfLongestSubstring(String s) {
//        int length = 0;
//        char ss[] = s.toCharArray();
//        int v[] = new int[ss.length];
//        int max = 1;
//        for (int i = 0; i < ss.length; i++) {
//            max = 1;
//            for (int j = 0; j < i; j++) {
//                if (ss[i] > ss[j] && max < v[j] + 1)
//                    max = v[j] + 1;
//            }
//            v[i] = max;
//        }
//        max = 1;
//        for (int i : v) {
//            max = i > max ? i : max;
//        }
//        return max;
//    }

    public static int lengthOfLongestSubstring(String s) {
        int max = 1;
        int counter = 0;
        for (int i = 0; i < s.length(); i++) {
            counter = 0;
            String ss = "";
            for (int j = i; j < s.length(); j++) {
                String temp = s.substring(j, j + 1);
                if (ss.contains(temp)) break;
                counter++;
                ss += s.substring(j, j + 1);
            }
            max = counter > max ? counter : max;
        }
        return max;
    }

    public static void main(String[] args) {
        String test = "pwwkew";
        int length = lengthOfLongestSubstring(test);
        System.out.println(length);
    }
}
